<script lang="ts" setup>
import axios from "axios";
import { ref, watchEffect } from "vue";

import useGetData from "@/store/get";

import {
  apiGetPostData,
  apiGetImgData,
  apiGetCatData,
  apiGetSearchData,
 
  apiGetConfigData,
  apiReviseConfigData,
} from "@/api/api";
// 实例化 store
const store = useGetData();

//新建一个变量，存储待渲染数据
const list = ref();

//发起一个get请求

//不鉴权拿值
const btGets = async () => {
  const a = await store.getPostData(2345);
  console.log(a);
  const params = {
    _fields: "categories,title,link,date,featured_media,author,id,content",
    include: 1,
  };
  apiGetPostData(params)
    .then((res) => {
      console.log(res);
      list.value = res;
    })
    .catch((error) => {
      console.log("有错误咯");
      console.log(error);
    });
};
//发起一个POST请求
const btPost = () => {
  apiReviseConfigData({
    crb_phone_numbers: "我修改了内容",
    crb_phone_numberss: "我也修改了内容",
  })
    .then((res) => {
      console.log("我执行咯");
      console.log(res);
    })
    .catch((error) => {
      console.log("有错误咯");
      console.log(error);
    });
};

interface Props {
  data: number;
  config: number;
}

const props = defineProps<Props>();

watchEffect(() => {
  console.log("监听中");
  console.log(props.data);
  console.log(props.config);
});
console.log("没有监听");
console.log(props.data);
console.log(props.config);
</script>

<template>
  {{ list }}
  <hr />
  11111
  {{ data }}
  {{ config }}

  <el-button type="primary" size="default" @click="btGets">
    发起GET请求 - 不鉴权
  </el-button>
  <el-button type="primary" size="default" @click="btPost">
    发起POST请求
  </el-button>
</template>

<style scoped></style>
